class Solution {
    public int[] searchRange(int[] nums, int target) {
        int[] ret = {-1, -1};
        if(nums.length == 0) return ret;
        int left = 0;
        int right = nums.length - 1;
        //找左端点
        while(left < right){
            int mid = left + (right - left) / 2;
            if(nums[mid] >= target){
                right = mid;
            }else {
                left = mid + 1;
            }
        }
        //跳出循环时，left == right，此时左端点找到了
        ret[0] = (nums[left] == target ? left : -1);
        left = 0;
        right = nums.length - 1;
        while(left < right){
            int mid = left + (right - left + 1) / 2;
            if(nums[mid] <= target){
                left = mid;
            }else{
                right = mid - 1;
            }
        }
        //跳出循环时，left == right，此时左端点找到了
        ret[1] = (nums[right] == target ? right : -1);

        return ret;
    }
}